<?php
/**
 * Created by PhpStorm.
 * User: Eric
 * Date: 2021/10/16
 * Time: 13:33
 */

namespace app\admin\controller;


use app\exception\HttpExceptions;
use think\facade\Db;
use think\Request;
class Manager extends AdminAuth
{
    public function modifyPass(Request $request) {
        $data = $request -> post();
        $password = Db::name('manager')->where('id',1)->value('password');
        $right = password_verify($data['opass'],$password);
        if($right) {
            $password = password_hash($data['pass'],PASSWORD_DEFAULT);
            Db::name('manager')->where('id',1)->update(['password' => $password]);
            return $this->result();
        }
        throw new HttpExceptions('旧密码错误！');
    }
    public function advise () {
        $advise = Db::name('manager')->where('id', 1) -> value('advise');
        return $this->result(compact('advise'));
    }
    public function adviseClear() {
       Db::name('manager') ->where('id',1)->update(['advise' => 0]);
       return $this->result();
    }

    public function adviseList(Request $request) {
        $page = $request->get('page');
        $size = $request->get('size');
        if(!is_numeric($page) || !is_numeric($size)) {
            throw new HttpExceptions('非法参数');
        }
        $sql = "select advise,uname,avatar,create_time from tb_advise a join tb_user u where a.uid = u.id order by a.id desc limit :start,:size";
        $start = ($page - 1) * $size;
        $list = Db::query($sql,compact('start','size'));
        $total = Db::name('advise')->count();
        return $this->result(compact('list','total'));
    }
}